/*
 **功能：调起微信扫码，扫码后获取码的内容，再剪切内容里的出sn码字符串
 **参数：无
 */
export const scanCodeGetSN = () => {
	return new Promise((resolve, reject) => {
		// 调起条码扫描
		uni.scanCode({
			scanType: ['qrCode'], // 设定为二维码
			success: (res) => {
				console.log('条码类型：' + res.scanType);
				console.log('条码内容：' + res.result);
				uni.showToast({
					title: '识别成功',
					icon: 'success'
				});
				let url = res.result;
				let startIndex = url.indexOf('sn=') + 3;
				let endIndex = url.indexOf(' ', startIndex);
				if (endIndex === -1) {
					endIndex = url.length;
				}
				let snValue = url.slice(startIndex, endIndex);
				resolve(snValue);
			},
			fail: (err) => {
				reject(err);
			}
		});
	});
};